package com.pj.project.file_info;

import java.beans.Transient;
import java.io.File;
import java.util.List;
import com.pj.utils.so.SoMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pj.utils.sg.*;

import static com.pj.project4sp.uploadfile.UploadUtil.uploadConfig;

/**
 * Service: file_info -- 升级信息
 * @author xxxxxx
 */
@Service
public class FileInfoService {

	/** 底层 Mapper 对象 */
	@Autowired
	FileInfoMapper fileInfoMapper;

	/** 增 */
	int add(FileInfo f){
		return fileInfoMapper.add(f);
	}

	/** 删 */
	@Transient
	int delete(Integer id){
		FileInfo file = fileInfoMapper.getById(id);
		File Folder = new File(file.getRootFolder() + "/" + file.getName());
		// 路径为文件且不为空则进行删除
		if (Folder.exists()) {
			Folder.delete();
		}
		return fileInfoMapper.delete(id);
	}

	/** 改 */
	int update(FileInfo f){
		return fileInfoMapper.update(f);
	}

	/** 查 */
	FileInfo getById(Integer id){
		return fileInfoMapper.getById(id);
	}

	/** 查集合 - 根据条件（参数为空时代表忽略指定条件） */
	List<FileInfo> getList(SoMap so) {
		return fileInfoMapper.getList(so);
	}

	List<FileInfo> getListNoPage(String so) {
		return fileInfoMapper.getListNoPage(so);
	}
	public FileInfo findFileByName(String fileName) {
		return fileInfoMapper.getByName(fileName);
	}

}
